require(["common", "coAjax", "queryString", "Cookies", "href"], function(jSouper, coAjax, QueryString, Cookies, href) {
	App.set("$Cache.sign_in.name", Cookies.get("cache_bus_login_name"));
	var queryString = new QueryString();

	/*
	 *登录
	 */

	//登录
	App.set("$Event.sign_in.common_login", function() {
		App.get("$Event.admin.login")();
	});


	// 卖家
	App.set("$Event.admin.login", function(argument) {
		var username = App.get("$Cache.sign_in.name");
		var password = App.get("$Cache.sign_in.password");
		coAjax.post(appConfig.bus.login + "?ignore_origin=true", {
			name: username,
			password: password
		}, function() {
			alert("success", "商家登录成功");
			Cookies.set("cache_bus_login_name", username);
			//使用消费者身份进行登录
			coAjax.post(appConfig.user.sign_in_url + "?from_bus=true", function(result) {
				var callbackUrl = queryString.get("cb_url");
				App.set("loginer", result.result);
				if (callbackUrl) {
					href.jump(callbackUrl);
				} else {
					href.jump("/main-beta.html");
				}
			});
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
		})
	});
	App.set("$Event.sign_in.to_password_input", function() {
		App.set("$Cache.sign_in.is_focus", true);
		App.set("$Cache.sign_in.is_focus", false);
	});
});